package com.engine.modules.ytht.service;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ListMapAndJson;
import com.engine.modules.speapi.mapper.SpecialGisMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author FY
 * @version 1.0.0
 * @ClassName LocationServiceImpl.java
 * @Description TODO
 * @createTime 2021年12月12日
 */
@Slf4j
@Service
@CacheConfig(cacheNames="locationCache")
public class LocationServiceImpl implements LocationService {

    @Autowired
    SpecialGisMapper specialGisMapper;

    @Override
    @Cacheable(key = "'LocationPolygon:'+#pac")
    public JSONObject getLocationPolygon(String pac) {
        List<Map<String, Object>> rsList= specialGisMapper.getLocationPolygon(pac);
        return  ListMapAndJson.ListMap2GeojsonObject(rsList);
    }

    @Override
    @Cacheable(key = "'LocationPolygon:'+#pac")
    public List<Map<String, Object>> getLocationPolygon2(String pac) {
        List<Map<String, Object>> ll = specialGisMapper.getLocationPolygon(pac);
        return ll;
    }

    @Override
    @Cacheable(key = "'LocationPolygon:YC'+#ycpac")
    public List<Map<String, Object>> getLocationPolygonByYCPac(String ycpac) {
        List<Map<String, Object>> ll = specialGisMapper.getLocationPolygonByYCPac(ycpac);
        return ll;
    }

    @Override
    @Cacheable(key = "'LocationPac:'+#lng+':'+#lat")
    public List<Map<String, Object>> getLocationPacByLngLat(float lng, float lat) {
        return specialGisMapper.getLocationPacByLngLat(lng,lat);
    }
}
